<template>
    <div id="login">
        <el-dialog width="100" :visible="true" :show-close="false">

            <div slot="title">
               <h2><img src="../assets/1.png" alt="">登陆界面</h2> 
            </div>

            <el-form label-position="left" label-width="80px">
                <el-form-item label="用户名">
                    <el-input v-model="form.username"></el-input>
                </el-form-item>

                <el-form-item label="密码">
                    <el-input v-model="form.password" type="password"></el-input>
                </el-form-item>
            </el-form>

            <div slot="footer" >
                <el-button type="primary" @click="login()">
                    登陆
                </el-button>
                
                <el-button type="text">
                    <router-link to="/regist">注册</router-link> 
                </el-button>
                
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: ""
      }
    };
  },
  created() {
    this.isLogin();
  },
  methods: {
    isLogin() {
      this.axios.get("/users/islogin").then((ret) => {
        const { data } = ret.data;
        if (data == 1) {
          this.$router.push('/home');
        }
      });
    },
    login() {
      this.axios.post("/users/login", { ...this.form })
        .then((ret) => {
          const { data,error } = ret.data;
          this.store.set('userInfo',data);
          this.$router.push({
            name: "home"
          });
        }).catch(() => {
          this.$message.error("用户名或密码错误");
        });
    }
  }
};
</script>

<style>
/* #login {

} */

.el-form {
  padding: 0 10px;
}
</style>
